<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsppages/include/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title><%=system_name%> - 选择物料清单</title>
	<base href="<%=basePath%>" />
	<link type="image/x-icon" rel="shortcut icon" href="<%=basePath%>images/favicon.ico" />
 	<meta http-equiv="pragma" content="no-cache" />
 	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />
	<link href="<%=basePath%>css/common.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/userlist.css" rel="stylesheet" type="text/css" />
	<script src="<%=basePath%>js/common.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/pagebar_cn.js"></script>

	<script type="text/javascript">
	var vals='';
	function getCheck(flag){ //flag为true时表示只允许选中单个
		var obj=document.getElementsByName("cb");
		var num=0,ids='';
		vals='';
		for(var i=0;i<obj.length;i++){
			if(obj[i].checked){
				num++;
				ids+=obj[i].id;
				ids+=',';
				vals+=obj[i].value;
				vals+=',';
			}
			if(num>1&&flag){
			 	alert("只能选择一个物料！");
			 	return '';
			 }
		}
		if(num==0){
			alert("请先选择物料！");
			return '';
		}
		ids = ids.substring(0,ids.length - 1); //将最后的逗号去掉
		vals = vals.substring(0,vals.length - 1);
		return ids;
	}
	//点击事件，IE与火狐的处理方式不同
	function clickA(id){ 
		if(document.all){ 
			document.getElementById(id).click(); 
		}else{ 
			//直接在新窗口中操作
			window.location.href=document.getElementById(id); 	
		} 
	}
	//选中点击确定返回
	function re(){
		var id=getCheck(true);
		if(id=='') return;
		var picName=vals;
		if(navigator.appVersion.indexOf("MSIE") == -1){
			window.opener.browsBack(id,picName);
		}else{
			window.dialogArguments.browsBack(id,picName);
		}
		window.close();
	}
	
	</script>
</head>

<body>
 <form id="searchForm" action="trade/showMaterialList" method="get" autocomplete="off">
 	<div style="text-align:center">物料清单：<input type="text" name="name" value="${shipMaterialSearchCond.name}"/> <input type="submit" class="btn1" value=" 搜索 " /></div>
 </form>
 
<a id="reload" name="reload" href="" style="display:none"></a>
	<table width="500" border="0" cellspacing="0" cellpadding="0" class="tb" style="margin-left:5px">
		<tr>
			<td class="t2" width="50"></td>
			<td class="t2" width="150">材料编码</td>
			<td class="t2" width="100">材料名称</td>
			<td class="t2" width="200">规格型号</td>
			<td class="t2" width="100">计量单位</td>
		</tr>
		<c:forEach var="shipMaterial" items="${shipMaterialList}">
		<tr>
				<td style="text-align:center"><input type="checkbox" id="${shipMaterial.id}" value="${shipMaterial.name}" name="cb"/></td>
				<td>${shipMaterial.code}</td>
				<td>${shipMaterial.name}</td>
				<td>${shipMaterial.format}</td>
				<td>${shipMaterial.unit}</td>
		</tr>
		</c:forEach>	
		<tr><td colspan="4" style="text-align:center"><input type="button" value=" 确定 " class="btn1" onclick="re()" /></td></tr>
	</table>
	
<script type="text/javascript">
 		//showModalDialog 调用无法正确获取url地址，需重写此方法
 		wpagebar.prototype.createUrl = function (page) {
        	if (isNaN(parseInt(page))) page = 1;
        	if (page < 1) page = 1;
        	if (page > this.pageCount) page = this.pageCount;
       		var url ="<%=basePath%>trade/showMaterialList";
        	var args = location.search;
        	var reg = new RegExp('([\?&]?)' + this.argName + '=[^&]*[&$]?', 'gi');
       		args = args.replace(reg,'$1');
        	if (args == '' || args == null) {
                args += '?' + this.argName + '=' + page;
        	} else if (args.substr(args.length - 1,1) == '?' || args.substr(args.length - 1,1) == '&') {
                args += this.argName + '=' + page;
        	} else {
                args += '&' + this.argName + '=' + page;
        	}
       		return url + args;
		}
		//showModalDialog 用self.location.href会重新打开页面，需重写此方法
		wpagebar.prototype.toPage = function(page){		
        	var turnTo = 1;
        	if (typeof(page) == 'object') {
                turnTo = page.options[page.selectedIndex].value;
        	} else {    	
                turnTo = page;
       	 	}       	 	
        	document.getElementById("reload").href =this.createUrl(turnTo);        	
        	clickA("reload");
		}
		
		var pageControl = new wpagebar('pageControl');
		pageControl.argName = "pageIndex";
		pageControl.pageCount =${searchStat.pageCount};
		pageControl.load();
</script>

</body>
</html>
